package edu.westga.vocalengineer.audio.gui;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

import edu.westga.vocalengineer.audio.transforms.PitchChangeTransform;

/**
 * PitchChangeGuiTransform
 *   Implements a PitchChangeTransform with an options panel.
 * @author mfarmer2
 */
public class PitchChangeGuiTransform 
	extends PitchChangeTransform 
	implements IGuiTransform {
	
	private JPanel optionsPanel;
	private JCheckBox pitchChangeEnabledCheck;
	private JTransformSliderPanel pitchChangeAmountSlider;	
	
	/**
	 * Sets up a PitchChangeGuiTransform, uses default values.
	 */
	public PitchChangeGuiTransform() {
		super(150);
		optionsPanel = new JPanel();
		pitchChangeEnabledCheck = new JCheckBox("Enable Pitch Change Transform");
		pitchChangeAmountSlider = new JTransformSliderPanel("Amount (percent):", 20, 220, 150);
		JPanel tempPanel = new JPanel();
		tempPanel.setLayout(new BoxLayout(tempPanel, BoxLayout.PAGE_AXIS));
		tempPanel.add(pitchChangeAmountSlider);
		optionsPanel.add(pitchChangeEnabledCheck);
		optionsPanel.add(Box.createRigidArea(new Dimension(20,20)));
		optionsPanel.add(tempPanel);
		optionsPanel.setBorder(BorderFactory.createLineBorder(Color.black));
	}
	
	/**
	 *  See AudioTransform.execute; applies an audio transform by
	 *  updating state to match sliders in options panel.
	 */
	@Override
	public short[] exectueWithGuiOptions(short[] samples) {
		if(!pitchChangeEnabledCheck.isSelected()) return samples;
		pitchChangeAmount = ((float)pitchChangeAmountSlider.getValue() / 100.0f);
		return execute(samples);
	}

	/**
	 * Returns the options JPanel.
	 */
	@Override
	public JPanel getOptionsPanel() {
		return optionsPanel;
	}

}
